package cn.tedu.csmall.config;

import cn.tedu.csmall.bean.User;
import cn.tedu.csmall.properties.UserProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 判断当前系统yaml文件是否存在 user.enable属性
 * 不存在 条件不满足,配置类不加载
 * 有这个属性 但是值不是true 条件也不满足
 */
@Configuration
@ConditionalOnProperty(
        prefix = "user",
        value = "enable",
        havingValue = "true",
        matchIfMissing = false
)
@EnableConfigurationProperties(UserProperties.class)
public class UserAutoConfiguration {

    @Bean
    public User user(UserProperties properties){
        User user=new User();
        user.setUsername(properties.getUsername());
        user.setPassword(properties.getPassword());
        return user;
    }
}
